﻿using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System;
using System.Collections.Generic;

    public class MiniStateMachine<T> where T : struct, IComparable, IConvertible, IFormattable
    {
        /// the current character's movement state
        public T CurrentState { get; protected set; }
        /// the character's movement state before entering the current one
        public T PreviousState { get; protected set; }

        /// <summary>
        /// Changes the current movement state to the one specified in the parameters, and triggers exit and enter events if needed
        /// </summary>
        /// <param name="newState">New state.</param>
        public virtual void ChangeState(T newState)
        {
            // if the "new state" is the current one, we do nothing and exit
            if (newState.Equals(CurrentState))
            {
                return;
            }

            // we store our previous character movement state
            PreviousState = CurrentState;
            CurrentState = newState;
        }

        /// <summary>
        /// Returns the character to the state it was in before its current state
        /// </summary>
        public virtual void RestorePreviousState()
        {
            // we restore our previous state
            CurrentState = PreviousState;
        }
}